package cn.hznc.domain.response;

/**
 * Demo class
 *
 * @author xiahuanyu
 * @date 2023/3/6
 */
public class Result {
    private String code;

    private String message;

    public Result(String code, String message) {
        this.code=code;
        this.message=message;
    }

    public Result() {
    }

    public Result(String code) {
        this.code=code;
    }

    /**
     * 失败消息
     *
     * @param errCode errCode
     * @param errMessage errMessage
     * @return
     */
    public static Result buildFailure(String errCode, String errMessage) {
        Result response = new Result();
        response.setCode(errCode);
        response.setMessage(errMessage);
        return response;
    }

    /**
     * 成功消息
     *
     */
    public static Result buildSuccess() {
        Result response = new Result();
        response.setSuccess();
        return response;
    }

    public boolean isSuccess() {
        return HttpCode.SUCCESS.getCode().equals(this.code);
    }

    protected void setSuccess() {
        this.code = HttpCode.SUCCESS.getCode();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "Response{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                '}';
    }

}
